#include <stdio.h>
#include "Jerasure-1.2A/cauchy.h"
#include "Jerasure-1.2A/jerasure.h"
#include "Jerasure-1.2A/galois.h"
#define K 4
#define M 2
#define W 8
#define CANARY_SIZE 16

char *decode(unsigned long size, char **data_ptrs, int *erased)
{
  int i, j;
  int *matrix;
  int dmatrix[K*K], dm_ids[K];
  char *data;

  matrix = cauchy_original_coding_matrix(K, M, W);
  jerasure_make_decoding_matrix(K, M, W, matrix, erased, dmatrix, dm_ids);

  data = malloc(size*K);
  for(i=0; i < 4; i++)
    for(j=0; j < 4; j++)
      galois_w08_region_multiply(data_ptrs[j], dmatrix[i*K+j], size,
                                 data+(i*size), j);
  return data;
}
